<template>
  <div class="header-info">
    <div class="control">
      <span>
        <el-icon><Message /></el-icon>
      </span>
      <span>
        <span class="dot"></span>
        <el-icon><ChatDotRound /></el-icon>
      </span>
      <span>
        <el-icon><Search /></el-icon>
      </span>
    </div>
    <div class="drop-down">
      <el-dropdown size="large">
        <span class="el-dropdown-link" aria-expanded="false">
          <div class="info">
            <el-avatar icon="UserFilled" size="small" />
            <span class="name">{{ userInfo.name }}</span>
          </div>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="handleExitClick">
              <el-icon><CircleClose /></el-icon>
              <span>退出系统</span>
            </el-dropdown-item>
            <el-dropdown-item divided>
              <el-icon><InfoFilled /></el-icon>
              <span>个人信息</span>
            </el-dropdown-item>
            <el-dropdown-item>
              <el-icon><Unlock /></el-icon>
              <span>修改密码</span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script setup lang="ts">
import { localCache } from '@/utils/cahe'
import { useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'

import useLoginAccountStore from '@/store/login/login'

// 账户名称的动态展示
const loginAccountStore = useLoginAccountStore()
const { userInfo } = storeToRefs(loginAccountStore)

const router = useRouter()
function handleExitClick() {
  localCache.removeCache('token')
  router.push('/login')
}
</script>

<style lang="less" scoped>
.header-info {
  display: flex;
  align-items: center;
}
.control {
  display: inline-flex;
  margin-right: 20px;

  span {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 35px;

    &:hover {
      background: #f2f2f2;
    }

    i {
      font-size: 20px;
    }

    .dot {
      position: absolute;
      top: 3px;
      right: 3px;
      z-index: 10;
      width: 6px;
      height: 6px;
      background: red;
      border-radius: 100%;
    }
  }
}
.drop-down {
  display: flex;
  align-items: center;
  cursor: pointer;
  .el-dropdown {
    --el-dropdown-menu-box-shadow: none;
  }
  .info {
    display: flex;
    align-items: center;
    .name {
      margin-left: 5px;
      text-shadow: 0.3px 0.4px #333;
    }
  }
}
</style>
